<template>
  <div class="channels_wrap">
    <BreadCrumb crumb="商品频道管理"></BreadCrumb>  

    <div class="top_bar">
       <Addchannels @fnResetTable="fnGetData"></Addchannels>       
    </div>

    <ChannelsTable :channels="aChannelsList" @fnResetTable="fnGetData"></ChannelsTable>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :page-size="pagesize"
      :current-page="page"
      style="text-align:center;margin-top:10px"
      @current-change="fnGetPage"
      >
    </el-pagination>
  </div>
</template>

<script>
import BreadCrumb from '@/components/widget/BreadCrumb'
import Addchannels from '@/components/widget/AddChannels'
import ChannelsTable from '@/components/widget/ChannelsTable'
import cons from '@/components/constant'

export default {
  name: 'Channels',
  data () {
    return {
      page:1,
      
      total:0,
      pagesize:3,
      aChannelsList:[]
    }
  },
  components:{
    BreadCrumb,
    Addchannels,
    ChannelsTable
  },
  // 周期函数
  mounted(){
    this.fnGetData(1);
  },
  methods:{
    // 获取所有频道组数据
    fnGetData(){
      // /v1/goods/groups/?page=1&pageSize=3  问号后面的是查询参数
      this.axios.get(cons.apis + '/v1/goods/groups/',{
        params:{
          page:this.page,
          pageSize:this.pagesize
        },
        headers:{
          Authorization: 'JWT' + localStorage.token
        },
        responseType: 'json',
      })
      .then((res) => {
        console.log('加载频道组的响应',res)
        if (res.status == 200){
          this.aChannelsList = res.data
        }else{
          this.$message({
            type:'error',
            message:'加载频道组失败'
          })
        }
      }).catch((err) => {
        console.log('请求失败',err)
      });
    },
    
  }
}
</script>

<style scoped>
.top_bar{
    width:95.2%;
    overflow:hidden;
    margin:10px auto;
  }
</style>
